<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="开发,">










<meta name="description" content="概述 关于vuew的开发网上已经有很多很多doc文档来介绍vue的使用，尤大神的东西在中国的推广使用也是非常成功的，中文的社区也越来越繁荣，上手程度对比其他架构有很突出的优势，学习曲线也很平滑，总结下来确实是一个非常好的一款前端架构。   不说废话，这里介绍一下在项目开发完毕以后，部署到Nginx上面做静态界面的过程。">
<meta name="keywords" content="开发">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue和Nginx连用反向代理静态界面">
<meta property="og:url" content="https://xxyuan.net/2018/09/28/Vue和Nginx连用反向代理静态界面/index.html">
<meta property="og:site_name" content="晓远Blog">
<meta property="og:description" content="概述 关于vuew的开发网上已经有很多很多doc文档来介绍vue的使用，尤大神的东西在中国的推广使用也是非常成功的，中文的社区也越来越繁荣，上手程度对比其他架构有很突出的优势，学习曲线也很平滑，总结下来确实是一个非常好的一款前端架构。   不说废话，这里介绍一下在项目开发完毕以后，部署到Nginx上面做静态界面的过程。">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2019-11-16T14:20:50.159Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Vue和Nginx连用反向代理静态界面">
<meta name="twitter:description" content="概述 关于vuew的开发网上已经有很多很多doc文档来介绍vue的使用，尤大神的东西在中国的推广使用也是非常成功的，中文的社区也越来越繁荣，上手程度对比其他架构有很突出的优势，学习曲线也很平滑，总结下来确实是一个非常好的一款前端架构。   不说废话，这里介绍一下在项目开发完毕以后，部署到Nginx上面做静态界面的过程。">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://xxyuan.net/2018/09/28/Vue和Nginx连用反向代理静态界面/">





  <title>Vue和Nginx连用反向代理静态界面 | 晓远Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?b7fbd9803fe7b8df6faf867c7b94ce2a";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">晓远Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://xxyuan.net/2018/09/28/Vue和Nginx连用反向代理静态界面/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="晓远">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="晓远Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Vue和Nginx连用反向代理静态界面</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-09-28T11:38:36+08:00">
                2018-09-28
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/开发/" itemprop="url" rel="index">
                    <span itemprop="name">开发</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h4 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h4><blockquote>
<p>关于vuew的开发网上已经有很多很多doc文档来介绍vue的使用，尤大神的东西在中国的推广使用也是非常成功的，中文的社区也越来越繁荣，上手程度对比其他架构有很突出的优势，学习曲线也很平滑，总结下来确实是一个非常好的一款前端架构。</p>
</blockquote>
<blockquote>
<p>不说废话，这里介绍一下在项目开发完毕以后，部署到Nginx上面做静态界面的过程。</p>
</blockquote>
<a id="more"></a>
<h5 id="建立一个webpack模板"><a href="#建立一个webpack模板" class="headerlink" title="建立一个webpack模板"></a>建立一个webpack模板</h5><h6 id="过程："><a href="#过程：" class="headerlink" title="过程："></a>过程：</h6><ol>
<li><p>node、npm环境（必须）</p>
</li>
<li><p>推荐使用淘宝镜像来使用</p>
</li>
</ol>
<blockquote>
<p>镜像地址：npm install -g cnpm –registry=<a href="https://registry.npm.taobao.org" target="_blank" rel="noopener">https://registry.npm.taobao.org</a></p>
<ol start="3">
<li>使用vue-cil</li>
</ol>
</blockquote>
<blockquote>
<p>全局安装 vue-cli</p>
</blockquote>
<blockquote>
<p>npm install –global vue-cli</p>
</blockquote>
<ol start="4">
<li>创建一个基于webpack 模板的新项目</li>
</ol>
<blockquote>
<p>vue init webpack new-project(项目的名称)</p>
</blockquote>
<blockquote>
<p>项目会初始化一系列的东西，请按照步骤一步步的初始化</p>
</blockquote>
<h6 id="项目生成以后效果"><a href="#项目生成以后效果" class="headerlink" title="项目生成以后效果"></a>项目生成以后效果</h6><blockquote>
<p>其中红线部分为第一个为编译以后的文件夹，一个为关联的库</p>
</blockquote>
<h6 id="项目关联库"><a href="#项目关联库" class="headerlink" title="项目关联库"></a>项目关联库</h6><blockquote>
<p>cnpm install (这里cnpm即为上边关联指向的淘宝镜像)</p>
</blockquote>
<h6 id="项目使用node运行起来"><a href="#项目使用node运行起来" class="headerlink" title="项目使用node运行起来"></a>项目使用node运行起来</h6><blockquote>
<p>npm run dev </p>
</blockquote>
<h5 id="项目编译打包"><a href="#项目编译打包" class="headerlink" title="项目编译打包"></a>项目编译打包</h5><blockquote>
<p>npm run build </p>
</blockquote>
<p>.</p>
<h6 id="生成结构"><a href="#生成结构" class="headerlink" title="生成结构"></a>生成结构</h6><p>###### </p>
<h5 id="Nginx对于编译打包完成的静态资源的代理"><a href="#Nginx对于编译打包完成的静态资源的代理" class="headerlink" title="Nginx对于编译打包完成的静态资源的代理"></a>Nginx对于编译打包完成的静态资源的代理</h5><blockquote>
<p>简单介绍一下Nginx在这里的作用，简单来讲就是监听端口，代理链接及对应的静态资源。对于Nginx的安装不再叙述，网上的介绍及博客有很多很多。</p>
</blockquote>
<blockquote>
<p>Nginx的配置</p>
</blockquote>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br></pre></td><td class="code"><pre><span class="line"></span><br><span class="line">#START-SITE</span><br><span class="line">server &#123;</span><br><span class="line">	listen 80;</span><br><span class="line">	server_name  xuxiaoyuan.top;</span><br><span class="line">	access_log  logs/xuxiaoyuan.top.access.log;</span><br><span class="line">	root   D:/wwwroot/xuxiaoyuan.top;</span><br><span class="line">	index  index.php default.php index.html index.htm default.html default.htm;</span><br><span class="line">	</span><br><span class="line">	include rewrite/xuxiaoyuan.top.conf;</span><br><span class="line">		</span><br><span class="line">	#START-ERROR-PAGE</span><br><span class="line">	error_page 403 /403.html;</span><br><span class="line">	error_page 404 /404.html;</span><br><span class="line">    error_page 502 /502.html;</span><br><span class="line">	#END-ERROR-PAGE</span><br><span class="line">	</span><br><span class="line">	#301-START</span><br><span class="line">	#301-END</span><br><span class="line">	</span><br><span class="line">	</span><br><span class="line">	#REFERER-START</span><br><span class="line">	#REFERER-END</span><br><span class="line">	</span><br><span class="line">	#PROXY-START</span><br><span class="line">	#PROXY-END</span><br><span class="line">	</span><br><span class="line">	#START-SSL</span><br><span class="line">	#END-SSL</span><br><span class="line">	</span><br><span class="line">	#START-PHP</span><br><span class="line">	location ~ \.php$ &#123;</span><br><span class="line">		root   D:/wwwroot/xuxiaoyuan.top;</span><br><span class="line">		fastcgi_pass   127.0.0.1:4571;</span><br><span class="line">		fastcgi_index  index.php;</span><br><span class="line">		fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;</span><br><span class="line">		include        fastcgi_params;</span><br><span class="line">    &#125;</span><br><span class="line">	#END-PHP</span><br><span class="line">&#125;</span><br><span class="line">#END-SITE</span><br></pre></td></tr></table></figure>
<blockquote>
<p>配置文件是在默认的基础上修改的，因为我用的是window版本的，本地来使用Nginx，所以指向的是盘文件所在的地址，通常需要在linux服务器上使用，请指向/文件夹/文件夹类似这样的目录结构。</p>
</blockquote>
<blockquote>
<p>域名设置，这里修改了hosts文件，将当前ip指向了这个xuxiaoyuan.top域名，正式环境用正常的域名来使用。</p>
</blockquote>
<h6 id="访问一下xuxiaoyuan-top域名，运行起来"><a href="#访问一下xuxiaoyuan-top域名，运行起来" class="headerlink" title="访问一下xuxiaoyuan.top域名，运行起来"></a>访问一下xuxiaoyuan.top域名，运行起来</h6><blockquote>
<p>最后，当前浏览器已经可以使用vue来生成的项目了，能做什么呢？首先，当一个静态界面来展示一些信息肯定是可以了，第二个左右就是对接移动端的H5接入开发，使用webview作为依托，使用vue生成H5来完成业务逻辑，可以使项目的包的大小在不增加的情况下，可以无限扩展。</p>
</blockquote>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/开发/" rel="tag"># 开发</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2018/08/06/再见深圳/" rel="next" title="再见深圳">
                <i class="fa fa-chevron-left"></i> 再见深圳
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2018/09/29/重构Jsbrige项目/" rel="prev" title="重构Jsbrige项目">
                重构Jsbrige项目 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">晓远</p>
              <p class="site-description motion-element" itemprop="description">这个一个关于博客的个人网站</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">51</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">3</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">37</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-4"><a class="nav-link" href="#概述"><span class="nav-number">1.</span> <span class="nav-text">概述</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#建立一个webpack模板"><span class="nav-number">1.1.</span> <span class="nav-text">建立一个webpack模板</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#过程："><span class="nav-number">1.1.1.</span> <span class="nav-text">过程：</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#项目生成以后效果"><span class="nav-number">1.1.2.</span> <span class="nav-text">项目生成以后效果</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#项目关联库"><span class="nav-number">1.1.3.</span> <span class="nav-text">项目关联库</span></a></li><li class="nav-item nav-level-6"><a class="nav-link" href="#项目使用node运行起来"><span class="nav-number">1.1.4.</span> <span class="nav-text">项目使用node运行起来</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#项目编译打包"><span class="nav-number">1.2.</span> <span class="nav-text">项目编译打包</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#生成结构"><span class="nav-number">1.2.1.</span> <span class="nav-text">生成结构</span></a></li></ol></li><li class="nav-item nav-level-5"><a class="nav-link" href="#Nginx对于编译打包完成的静态资源的代理"><span class="nav-number">1.3.</span> <span class="nav-text">Nginx对于编译打包完成的静态资源的代理</span></a><ol class="nav-child"><li class="nav-item nav-level-6"><a class="nav-link" href="#访问一下xuxiaoyuan-top域名，运行起来"><span class="nav-number">1.3.1.</span> <span class="nav-text">访问一下xuxiaoyuan.top域名，运行起来</span></a></li></ol></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-snowflake-o"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">晓远</span>

  
</div>









        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
